//
//  UserBSLoginWithPassWord.m
//  Teacher
//
//  Created by 李飞 on 15/10/27.
//  Copyright (c) 2015年 xueyinyue. All rights reserved.
//

#import "UserBSLoginWithPassWord.h"
#import "ApplicationContext.h"
#import "ApiConfig.h"

@implementation UserBSLoginWithPassWord

- (id)onExecute {
    
    //创建参数字典
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:_userName forKey:@"phone"];
    [params setObject:kSystemType forKey:@"systemType"];
    [params setObject:kVersionCode forKey:@"versionCode"];
    [params setObject:_password forKey:@"password"];
    
    //发送请求，获取结果
    id result = [self remoteJSON:@"POST" url:[ApiConfig urlApiUserLoginWithPassWord] params:params];
    
    
    NSNumber* returnState = result[@"error"];
    
    UserBSLoginWithPassWordResult *serviceResult = [[UserBSLoginWithPassWordResult alloc] init];
    
    if ([returnState isEqualToNumber:@0]){
        
        serviceResult.isLoginSuccess = YES;
        serviceResult.isGotoUserInfo = result[@"data"][@"infoSet"];
        
        NSLog(@"密码登录成功:%@",result[@"data"][@"token"]);
        [ApplicationContext instance].token = result[@"data"][@"token"];
        
        
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        [ud setObject:[ApplicationContext instance].token forKey:@"token"];
    }
    else
    {
        serviceResult.isLoginSuccess = NO;
        serviceResult.message = result[@"msg"];
    }
    
    return serviceResult;
    
}

@end

@implementation UserBSLoginWithPassWordResult {
    
}
@end